// Login Form

$(function() {
    var button = $('#loginButton');
    var box = $('#loginBox');
    var form = $('#loginForm');
    button.removeAttr('href');
    button.mouseup(function(login) {
        box.toggle();
        button.toggleClass('active');
    });
    form.mouseup(function() { 
        return false;
    });
    $(this).mouseup(function(login) {
        if(!($(login.target).parent('#loginButton').length > 0)) {
            button.removeClass('active');
            box.hide();
        }
    });
});

function isUser(){
document.getElementById("namediv").innerHTML="一卡通";

}
function isLeague(){
document.getElementById("namediv").innerHTML="用户名";
}

var xmlHttp=false;

function on()
{
	try
	 {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	 }
	catch (e)
	 {
			// Internet Explorer
		 try
			  {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			  }
		 catch (e)
			  {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
	 }
	 if(!xmlHttp)
	 {
		alert("无法创建对象!");
	 }
	var url="http://herald.seu.edu.cn/AccountCenter/SignOn";
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=deepOutPut;
	xmlHttp.send(null);
}
function deepOutPut()
{
	if (xmlHttp.readyState==4 && xmlHttp.status==200)
	{
	    
		var getStr=xmlHttp.responseText;	
		if(getStr.length < 500 )
		{
			var url="http://herald.seu.edu.cn/league_p/getUserInfo.php";
			
			xmlHttp.open("GET",url,true);
			xmlHttp.onreadystatechange =function fin()
			{
				
				if (xmlHttp.readyState==4 && xmlHttp.status==200)
				{
					var getStr=xmlHttp.responseText;
					if(getStr == "fail")
					{
						alert("系统错误");
					}
					document.getElementById("cardNum").innerHTML="<span class='userInfor'>"+getStr+"</span>";
					document.getElementById("loginButton").style.display='none';
					document.getElementById("head_logout").innerHTML="<span class='userInfor'>退出</span>";
					document.getElementById("loginBox").innerHTML="";
				}
			}
			xmlHttp.send(null);
		}
	}
}
function select()
{   
try
	 {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	 }
	catch (e)
	 {
			// Internet Explorer
		 try
			  {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			  }
		 catch (e)
			  {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
	 }
	 if(!xmlHttp)
	 {
		alert("无法创建对象!");
	 }
	var url="http://herald.seu.edu.cn/league_p/select.php";
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange =function check()
	{
		
		if (xmlHttp.readyState==4 && xmlHttp.status==200)
		{
			var getStr=xmlHttp.responseText;
			if(getStr == "Go")
			{
				on();
			}
		}
	}
	xmlHttp.send(null);
	
}